#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
using namespace std;

class Date
{
public:
    Date(int year = 1990, int month = 1, int day = 1)
    {
        _year = year;
        _month = month;
        _day = day;
    }
    void Printf()
    {
        printf("%02d-%02d-%02d\n", _year, _month, _day);
    }
    Date& AfterMonthDay(int day);
private:
    int _year;
    int _month;
    int _day;
};

int GetMonthDay(int year, int month)
{
    int Day[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
    if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0))
    {
        return 29;
    }
    return Day[month];
}

Date& Date::AfterMonthDay(int day)
{
    _day += day;
    while (_day > GetMonthDay(_year, _month))
    {
        _day -= GetMonthDay(_year, _month);
        _month++;
        if (_month == 13)
        {
            _year++;
            _month = 1;
        }
    }
    return *this;
}

int main()
{
    int year, month, day, d, n;
    cin >> n;
    while (n > 0)
    {
        cin >> year >> month >> day >> d;
        Date d1(year, month, day);
        d1.AfterMonthDay(d);
        d1.Printf();
        n--;
    }
}

